package jee.boot.module.bpm.table.mysql.model;

import jee.boot.common.utils.StringUtils;

/**
 * 字符串类型,(长文本)
 */
public class TextField extends FormField {
    public TextField() {
        setColumnType("LONGTEXT");
        setNullable(true);
        setCreate(true);
    }

    /**
     * 新建表字段的sql
     *
     * @return
     */
    @Override
    public String getCreateColumn() {
        StringBuilder sql = new StringBuilder();
        sql.append(getColumnName()).append(" ");
        sql.append(getColumnType()).append(" ");
        if (!getNullable()) {
            sql.append("NOT NULL").append(" ");
        }
        sql.append("COMMENT").append(" ").append("'").append(getComment()).append("'");
        return sql.toString();
    }

    /**
     * 复写equals,用于确认字段的变更
     *
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof TextField)) {
            return false;
        }
        TextField eobj = (TextField) obj;
        if (!StringUtils.equals(this.getComment(), eobj.getComment())) {
            return false;
        }
        if (!this.getNullable().equals(eobj.getNullable())) {
            return false;
        }

        return true;
    }
}
